package thread.lock;

import thread.ThreadUtils;

public class WaitTest {
    public static final Object MONITOR = new Object();

    public static void main(String[] args) {
        new Thread(()->{
            synchronized (MONITOR){
                System.out.println("线程一开始了");
                try {
                    MONITOR.wait();  //等待
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程一结束了");

            }

        }).start();

        new Thread(()->{
            synchronized (MONITOR){
                System.out.println("线程二开始了");
                ThreadUtils.sleep(2000);
                MONITOR.notify(); //通知
                System.out.println("线程二结束了");

            }

        }).start();
    }
}
